Ext.namespace('VAS');



VAS.DynamicFormWindow = function($config) {
	var _this = this;
	var data = SyncAjax($config.formPanel.url,{
		
	});	
	var formPanel = new VAS.DynamicEditForm({
		id                : $config.formPanel.id,
		fieldSet          : data.fieldSet
	});
	var loadUrl = data.fieldSet.loadUrl
	if(loadUrl.indexOf('?')>-1){
		loadUrl += '&' + 10*Math.random();
	}else{
		loadUrl += '?' + 10*Math.random();
	}
	formPanel.getForm().load({
			    waitTitle   : '正在加载中...',
				waitMsg     : '正在向服务器发送请求', 
	 			url         : loadUrl,
	 			success     : function(form,action) {
	 			
	 				
	 			},
	 			failure     : function(form,action) {
	 				Ext.Msg.alert("失败",action.result.msg);
	 			}
	});
	
	this.saveBt = {
			text : '保存',
			handler : function() {
				if (formPanel.getForm().isValid()) {
					formPanel.getForm().submit({
						url : data.action +"?formPanelId="+$config.formPanel.id,
						waitTitle : '正在提交',
						waitMsg : '正在向服务器发送请求',
						clientValidation : true,
						success : function(form, action) {
							Ext.Msg.alert('提示', '提交保存成功!', function() {
								formPanel.getForm().reset();
								$config.grid.store.reload();
							});
						},
						failure : function(form, action) {
							if (action.failureType == Ext.form.Action.CLIENT_INVALID) {
								Ext.Msg.alert('提示', '输入的信息不符合规格，请按照提示重新输入！');
							} else {
								alertFailure(action.result);
							}
						}
					});
				} 
			}
		};
		
		
	var thisConfig = {
		closeAction       : 'close',
		alwaysOnTop       : true,
		layout            : 'fit',
		items             : formPanel,
		buttons           : [this.saveBt]
		
	};
	var _config = $config || {};

	Ext.apply(_this, Ext.apply(thisConfig, _config));
	VAS.DynamicFormWindow.superclass.constructor.call(_this);

};

Ext.extend(VAS.DynamicFormWindow,VAS.BasicWindow,{
	
	
});
Ext.reg('dynamicform-win',VAS.DynamicFormWindow);



